package httpagent;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class NotifyHost {
	
	//private static final String DEFAULT_SERVER_ADDRESS = "http://localhost:8888";
	private static final String DEFAULT_SERVER_ADDRESS = "http://proxy-hoster.appspot.com";

	public static void main (String... args){
		
		String port;
		
		if (args.length > 0){
			port = args[0];
		} else{
			port = "8080";
		}
		
		List<NameValuePair> formparams = new ArrayList<NameValuePair>();
		formparams.add(new BasicNameValuePair("secureCode", "taylor"));
		formparams.add(new BasicNameValuePair("appName", "TestApp"));
		formparams.add(new BasicNameValuePair("port", port));
		
		UrlEncodedFormEntity entity = null;
		try {
			entity = new UrlEncodedFormEntity(formparams, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		HttpPost httppost = new HttpPost(DEFAULT_SERVER_ADDRESS +"/signhost");
		httppost.setEntity(entity);
		
		HttpClient httpclient = new DefaultHttpClient();
		try {
			HttpResponse response = httpclient.execute(httppost);
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		System.out.println("OK");
	}
	
}
